//Copyright (c) 2017. 章钦豪. All rights reserved.
package com.wandousoushu.jiusen.booksource.bean;

import java.util.Objects;

import static android.text.TextUtils.isEmpty;

/**
 * 书本信息
 */
public class BookInfoBean
{

    private String name; //小说名
    private String tag;
    private String noteUrl;  //如果是来源网站,则小说根地址,如果是本地则是小说本地MD5
    private String chapterUrl;  //章节目录地址,本地目录正则
    private long finalRefreshData;  //章节最后更新时间
    private String coverUrl; //小说封面
    private String author;//作者
    private String introduce; //简介
    private String origin; //来源
    private String charset;//编码
    private String bookSourceType;
    private String bookInfoHtml;
    private String chapterListHtml;

    private int type;//类型 1书架 2书城 3收藏夹

    public BookInfoBean()
    {
    }

    public BookInfoBean(String name, String tag, String noteUrl, String chapterUrl, long finalRefreshData, String coverUrl, String author, String introduce,
                        String origin, String charset, String bookSourceType)
    {
        this.name = name;
        this.tag = tag;
        this.noteUrl = noteUrl;
        this.chapterUrl = chapterUrl;
        this.finalRefreshData = finalRefreshData;
        this.coverUrl = coverUrl;
        this.author = author;
        this.introduce = introduce;
        this.origin = origin;
        this.charset = charset;
        this.bookSourceType = bookSourceType;
    }

    public int getType() {
        return type;
    }

    public void setType(int type) {
        this.type = type;
    }

    public String getName()
    {
        return name;
    }

    public void setName(String name)
    {
        this.name = name;
    }

    public String getTag()
    {
        return tag;
    }

    public void setTag(String tag)
    {
        this.tag = tag;
    }

    public String getNoteUrl()
    {
        return noteUrl;
    }

    public void setNoteUrl(String noteUrl)
    {
        this.noteUrl = noteUrl;
    }

    public String getChapterUrl()
    {
        return chapterUrl;
    }

    public void setChapterUrl(String chapterUrl)
    {
        this.chapterUrl = chapterUrl;
    }

    public long getFinalRefreshData()
    {
        return finalRefreshData;
    }

    public void setFinalRefreshData(long finalRefreshData)
    {
        this.finalRefreshData = finalRefreshData;
    }

    public String getCoverUrl()
    {
        return coverUrl;
    }

    public void setCoverUrl(String coverUrl)
    {
        this.coverUrl = coverUrl;
    }

    public String getAuthor()
    {
        return author;
    }

    public void setAuthor(String author)
    {
        this.author = formatAuthor(author);
    }

    public String getIntroduce()
    {
        return introduce;
    }

    public void setIntroduce(String introduce)
    {
        this.introduce = introduce;
    }

    public String getOrigin()
    {
        return origin;
    }

    public void setOrigin(String origin)
    {
        this.origin = origin;
    }

    public String getCharset()
    {
        return this.charset;
    }

    public void setCharset(String charset)
    {
        this.charset = charset;
    }

    public String getBookSourceType()
    {
        return this.bookSourceType;
    }

    public void setBookSourceType(String bookSourceType)
    {
        this.bookSourceType = bookSourceType;
    }

    public String getBookInfoHtml()
    {
        return bookInfoHtml;
    }

    public void setBookInfoHtml(String bookInfoHtml)
    {
        this.bookInfoHtml = bookInfoHtml;
    }

    public String getChapterListHtml()
    {
        return chapterListHtml;
    }

    public void setChapterListHtml(String chapterListHtml)
    {
        this.chapterListHtml = chapterListHtml;
    }

    public static String formatAuthor(String author)
    {
        if (author == null)
        {
            return "";
        }
        return author.replaceAll("作\\s*者[\\s:：]*", "").replaceAll("\\s+", " ").trim();
    }

    public boolean equals(Object obj){
        if (obj instanceof BookSourceBean)
        {
            BookInfoBean bookInfoBean =(BookInfoBean) obj;
            return stringEquals(name,bookInfoBean.name)
                    &&stringEquals(noteUrl,bookInfoBean.noteUrl)
                    &&stringEquals(author,bookInfoBean.author)
                    &&stringEquals(origin,bookInfoBean.origin)
                    &&stringEquals(chapterUrl,bookInfoBean.chapterUrl);
        }
        return false;
    }

    private Boolean stringEquals(String str1, String str2)
    {
        return Objects.equals(str1, str2) || (isEmpty(str1) && isEmpty(str2));
    }

}